/* This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package com.l2jfrozen.gameserver.model.actor.instance;

import com.l2jfrozen.gameserver.ai.CtrlIntention;
import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
import com.l2jfrozen.gameserver.model.zone.L2ZoneType;
import com.l2jfrozen.gameserver.model.zone.L2ZoneManager;
import com.l2jfrozen.gameserver.model.L2Character;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
import com.l2jfrozen.gameserver.managers.TownManager;

import javolution.text.TextBuilder;

public class L2ElfokeeperInstance extends L2FolkInstance
{
  public L2ElfokeeperInstance(int objectId, L2NpcTemplate template)
  {
    super(objectId, template);
  }

  public void onBypassFeedback(L2PcInstance player, String command)
  {
	      if(player == null)
	      {
	         return;
	      }

	      if(command.startsWith("giran"))
	      {
	    	  player.teleToLocation(82698, 148638, -3473);
	      }

	      if(command.startsWith("aden"))
	      {
	    	  player.teleToLocation(147456, 26886, -2207);
	      }

	      if(command.startsWith("goddard"))
	      {
	    	  player.teleToLocation(147725, -56517, -2780);
	      }

	      if(command.startsWith("ti"))
	      {
	    	  player.teleToLocation(-83838, 242732, -3732);
	      }
	      
	      if(command.startsWith("elv"))
	      {
	    	  player.teleToLocation(45873, 49288, -3059);
	      }
	      
	      if(command.startsWith("delv"))
	      {
	    	  player.teleToLocation(12428, 16551, -4588);
	      }
	      
	      if(command.startsWith("dwarf"))
	      {
	    	  player.teleToLocation(116551, -182493, -1525);
	      }
	      
	      if(command.startsWith("orc"))
	      {
	    	  player.teleToLocation(-44133, -113911, -244);
	      }
	      
	      if(command.startsWith("oren"))
	      {
	    	  player.teleToLocation(82321, 55139, -1529);
	      }
	      
	      if(command.startsWith("dion"))
	      {
	    	  player.teleToLocation(18748, 145437, -3132);
	      }
	      
	      if(command.startsWith("heine"))
	      {
	    	  player.teleToLocation(111383, 219107, -3546);
	      }
	      
	      if(command.startsWith("gludio"))
	      {
	    	  player.teleToLocation(-14225, 123540, -3121);
	      }
	      
	      if(command.startsWith("stut"))
	      {
	    	  player.teleToLocation(87358, -141982, -1336);
	      }
	      
	      if(command.startsWith("gludin"))
	      {
	    	  player.teleToLocation(-83063, 150791, -3128);
	      }
	      
	      if(command.startsWith("floran"))
	      {
	    	  player.teleToLocation(17144, 170156, -3502);
	      }
	      
	      if(command.startsWith("rune"))
	      {
	    	  player.teleToLocation(44070, -50243, -796);
	      }
	      
  }

  public void onAction(L2PcInstance player)
  {
    if (!canTarget(player)) {
      return;
    }

    if (this != player.getTarget())
    {
      player.setTarget(this);

      player.sendPacket(new MyTargetSelected(getObjectId(), 0));

      player.sendPacket(new ValidateLocation(this));
    }
    else if (!canInteract(player))
    {
      player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
    }
    else
    {
      showHtmlWindow(player);
    }

    player.sendPacket(new ActionFailed());
  }

  private void showHtmlWindow(L2PcInstance activeChar)
  {
    NpcHtmlMessage nhm = new NpcHtmlMessage(5);
    TextBuilder tb = new TextBuilder("");
    
    tb.append("<html><head><title>Cat:</title></head><body>");
    tb.append("<center>");
    tb.append("<table width=\"250\" cellpadding=\"5\" bgcolor=\"000000\">");
    tb.append("<tr>");
    tb.append("<td width=\"45\" valign=\"top\" align=\"center\"><img src=\"L2ui_ch3.menubutton4\" width=\"38\" height=\"38\"></td>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Event Gatekeeper</font>");  
    tb.append("<br1><font color=\"00FF00\">"+activeChar.getName()+"</font>, here you can spy who's where.</td>");
    tb.append("</tr>");
    tb.append("</table>");
    tb.append("</center>");
    tb.append("<center>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Where you gonna teleport " + activeChar.getName()+".</font><br>");  
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Talking I. : " + pewpew(2)+".</font>"); 
    tb.append("<button value=\"Talking I.\" action=\"bypass -h npc_" + getObjectId() + "_ti\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Elven V. : " + pewpew(3)+".</font>"); 
    tb.append("<button value=\"Elven V.\" action=\"bypass -h npc_" + getObjectId() + "_elv\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside D.Elven V. : " + pewpew(1)+".</font>"); 
    tb.append("<button value=\"D.Elven V.\" action=\"bypass -h npc_" + getObjectId() + "_delv\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Orc V. : " + pewpew(4)+".</font>"); 
    tb.append("<button value=\"Orc V.\" action=\"bypass -h npc_" + getObjectId() + "_orc\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Dwarven V. : " + pewpew(6)+".</font>"); 
    tb.append("<button value=\"Dwarven V.\" action=\"bypass -h npc_" + getObjectId() + "_dwarf\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Giran : " + pewpew(9)+".</font>"); 
    tb.append("<button value=\"Giran\" action=\"bypass -h npc_" + getObjectId() + "_giran\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Aden : " + pewpew(12)+".</font>"); 
    tb.append("<button value=\"Aden\" action=\"bypass -h npc_" + getObjectId() + "_aden\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Gludio : " + pewpew(7)+".</font>");  
    tb.append("<button value=\"Gludio\" action=\"bypass -h npc_" + getObjectId() + "_gludio\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Gludin : " + pewpew(5)+".</font>");  
    tb.append("<button value=\"Gludin\" action=\"bypass -h npc_" + getObjectId() + "_gludin\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Dion : " + pewpew(8)+".</font>");  
    tb.append("<button value=\"Dion\" action=\"bypass -h npc_" + getObjectId() + "_dion\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Oren : " + pewpew(10)+".</font>");  
    tb.append("<button value=\"Oren\" action=\"bypass -h npc_" + getObjectId() + "_oren\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Heine : " + pewpew(15)+".</font>");  
    tb.append("<button value=\"Heine\" action=\"bypass -h npc_" + getObjectId() + "_heine\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Rune : " + pewpew(14)+".</font>");  
    tb.append("<button value=\"Rune\" action=\"bypass -h npc_" + getObjectId() + "_rune\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Goddard : " + pewpew(13)+".</font>");  
    tb.append("<button value=\"Goddard\" action=\"bypass -h npc_" + getObjectId() + "_goddard\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Schuttgart : " + pewpew(17)+".</font>");  
    tb.append("<button value=\"Schuttgart\" action=\"bypass -h npc_" + getObjectId() + "_stut\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Players Inside Floran : " + pewpew(16)+".</font>");  
    tb.append("<button value=\"Floran\" action=\"bypass -h npc_" + getObjectId() + "_floran\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"><br>");
    tb.append("</center>");
    tb.append("<center>");
    tb.append("<img src=\"l2ui_ch3.herotower_deco\" width=256 height=32 align=center>");
    tb.append("<font color=\"FF6600\">Vespertine Chronicles</font>");  
    tb.append("</center>");
    tb.append("</body></html>");

    nhm.setHtml(tb.toString());
    activeChar.sendPacket(nhm);

    activeChar.sendPacket(new ActionFailed());
  }

  public static int pewpew(int bitch)
  {
  			L2ZoneType zone = TownManager.getInstance().getTown(bitch);
			int i = 0;
			if(zone != null)
			{
				for (L2Character character : zone.getCharactersInside().values())
                  if (character instanceof L2PcInstance)
                      i++;
                  return i;
			}
			return -1;
  }



}